package cn.bx.bid.service;

import cn.bx.bid.dao.ProfessorDao;
import cn.bx.bid.entity.Page;
import cn.bx.bid.entity.Professor;
import cn.bx.bid.entity.Project;
import cn.bx.bid.entity.WorkHistory;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

//M V C
@Service
public class ProfessorService {
	@Resource
	ProfessorDao professorDao;
	public static final int PAGE_SIZE = Page.PAGE_SIZE;

//修改
	public int update(Professor p){
		return professorDao.update(p);
	}

	//删除
    public int del(long id){
		return professorDao.del(id);
	}

	//批量删除
	public int ProfessorbatchDel(@Param("ids") long[] ids){
		return professorDao.ProfessorbatchDel(ids);
	}
//	public int add(User u) {
//		SqlSession s = MyBatisUtil.get();
//		try {
//			UserDao userDao = s.getMapper(UserDao.class);
//			return userDao.add(u);
//		} finally {
//			s.commit();
//			MyBatisUtil.close(s);
//		}
//	}
//	public int update(User u) {
//		SqlSession s = MyBatisUtil.get();
//		try {
//			UserDao userDao = s.getMapper(UserDao.class);
//			return userDao.update(u);
//		} finally {
//			s.commit();
//			MyBatisUtil.close(s);
//		}
//	}
//	public int batchDel(long[] ids) {
//		SqlSession s = MyBatisUtil.get();
//		try {
//			UserDao userDao = s.getMapper(UserDao.class);
//			return userDao.batchDel(ids);
//		} finally {
//			s.commit();
//			MyBatisUtil.close(s);
//		}
//	}


	public Page<Professor> paging(int pageNo, int limit, String professorname, String mobliephone, String identitynumber) {

		//SqlSession s = MyBatisUtil.get();
		//try {
		//	ProfessorDao userDao = s.getMapper(ProfessorDao.class);
			List<Professor> list = professorDao.search(pageNo, limit, professorname, mobliephone, identitynumber);
			int total = professorDao.searchTotal(professorname, mobliephone, identitynumber);
			Page<Professor> p = new Page<Professor>(total, limit, list,pageNo);
			return p;
		//} finally {
		//	MyBatisUtil.close(s);
	//	}

	}

	public Professor get(long id) {
	//	SqlSession s = MyBatisUtil.get();
		//try {
		//	ProfessorDao userDao = s.getMapper(ProfessorDao.class);

			 Professor p = professorDao.get(id);
			return p;
	//	} finally {
		//	MyBatisUtil.close(s);
		//}
	}

    public int delHis(long id, long hisid) {

		//	SqlSession s = MyBatisUtil.get();
			/*try {
				ProfessorDao userDao = s.getMapper(ProfessorDao.class);
*/
				int p = professorDao.delHis(id,hisid);
				return p;
		/*	} finally {
				MyBatisUtil.close(s);
			}*/

    }

	public int addHistory(WorkHistory w) {
		//SqlSession s = MyBatisUtil.get();
		/*try {
			ProfessorDao userDao = s.getMapper(ProfessorDao.class);
*/
			int p = professorDao.addHistory(w);
			return p;
		/*} finally {
			MyBatisUtil.close(s);
		}*/
	}
	public List<Project>  findProjs(long  profid) {
	//	SqlSession s = MyBatisUtil.get();
		/*try {
			ProfessorDao userDao = s.getMapper(ProfessorDao.class);
*/
			List<Project> p = professorDao.findProjs(profid);
			return p;
		/*} finally {
			MyBatisUtil.close(s);
		}*/
	}
	public int add(Professor p){
		int p1=professorDao.add(p);
		return p1;
	}
//	public User get(long id) {
//		SqlSession s = MyBatisUtil.get();
//		try {
//			UserDao userDao = s.getMapper(UserDao.class);
//			return userDao.get(id);
//
//		} finally {
//			MyBatisUtil.close(s);
//		}
//	}
}
